package com.chukun.flink.stream.operator.base;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import scala.Tuple1;
import scala.Tuple2;

/**
 * @author chukun
 * @version 1.0.0
 * @description filter 操作符
 * @createTime 2022年05月10日 00:06:00
 */
public class FilterOperator {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStream<Long> streamSource = env.fromSequence(1,5);

        DataStream<Long> resultStream = streamSource.filter(new FilterFunction<Long>() {

            @Override
            public boolean filter(Long aLong) throws Exception {
                if (aLong == 2L || aLong == 4L) {
                    return false;
                }
                return true;
            }
        });

        resultStream.print("输出结果");

        // 触发程序执行
        env.execute("filter stream");
    }
}
